#include <assert.h>
#include <stdio.h>
#include "idea.h"
#include "io.h"


static void test1(void)
{
    bit_array test1_bits[IDEA_INITIAL_KEYS * 16] = {0};

    short test1_index = 0;
    for (uint16_t i = 0; i < 8; i++) {
        hex2bits(test1_bits, test1_index, i);
        test1_index += 16;
    }
    uint16_t subkeys[IDEA_SUBKEYS] = {0};
    generate_subkeys(test1_bits, subkeys);

    static const uint16_t correct_subkeys[IDEA_SUBKEYS] = {
        0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
        0x0200, 0x0400, 0x0600, 0x0800, 0x0A00, 0x0C00, 0x0E00, 0x0000,
        0x000C, 0x0010, 0x0014, 0x0018, 0x001C, 0x0000, 0x0004, 0x0008,
        0x2000, 0x2800, 0x3000, 0x3800, 0x0000, 0x0800, 0x1000, 0x1800,
        0x0060, 0x0070, 0x0000, 0x0010, 0x0020, 0x0030, 0x0040, 0x0050,
        0xE000, 0x0000, 0x2000, 0x4000, 0x6000, 0x8000, 0xA000, 0xC000,
        0x0040, 0x0080, 0x00C0, 0x0100
    };
    for (int i = 0; i < IDEA_SUBKEYS; i++) {
        assert(subkeys[i] == correct_subkeys[i]);
    }
    printf("Test1 Passed!\n");
}


int main(void)
{
    test1();
    printf("All Tests Passed!\n");
    return 0;
}
